package com.wanmait.shoppingsys.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.wanmait.shoppingsys.util.DbHelper;
import com.wanmait.shoppingsys.vo.Type;

public class TypeDAO {
  private static TypeDAO typeDAO;
  private TypeDAO() {
	  
  }
  public static TypeDAO getDAO() {
	  if(typeDAO==null) {
		  typeDAO=new TypeDAO();
	  }
	  return typeDAO;
  }
  
  public ArrayList<Type> findAll(){
	  ArrayList<Type> types = new ArrayList<Type>();
	  
	  String sql="select * from type";
	  
	  Connection conn = DbHelper.getConn();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			rs = ps.executeQuery();
			while(rs.next()) {
				Type type=new Type();
				type.setId(rs.getInt("id"));
				type.setKind(rs.getString("kind"));
				types.add(type);
			}
		}catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			DbHelper.close(rs, ps, conn);
		}
		return types;
  }
  
  
}
